package com.sky.controller.admin;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.WorkspaceService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 工作台相关接口
 */
@RestController
@RequestMapping("/admin/workspace")
@Api(tags = "工作台")
@Slf4j
public class WorkspaceController {
    @Autowired
    private WorkspaceService workspaceService;
    /**
     * 今日数据接口
     * @return 包含新增用户数，订单完成率，营业额，平均客单价，有效订单数的VO
     */
    @GetMapping("/businessData")
    @ApiOperation("今日数据接口")
    public Result<BusinessDataVO> businessData() {
        log.info("今日数据");
        LocalDateTime beginTime=LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime endTime=LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        return Result.success(workspaceService.businessData(beginTime,endTime));
    }

    /**
     * 订单管理接口
     * @return 统计各种状态的订单数量，存放到VO中
     */
    @GetMapping("/overviewOrders")
    @ApiOperation("订单管理接口")
    public Result<OrderOverViewVO> overviewOrders() {
        log.info("工作台：订单管理");
        return Result.success(workspaceService.overviewOrders());
    }

    /**
     * 菜品总览接口
     * @return 统计停售和起售的菜品的数量，存放到VO中
     */
    @GetMapping("/overviewDishes")
    @ApiOperation("菜品总览接口")
    public Result<DishOverViewVO> overviewDishes() {
        log.info("工作台：菜品管理");
        return Result.success(workspaceService.overviewDishes());
    }

    /**
     * 套餐总览接口
     * @return 统计停售和起售的套餐的数量，存放到VO中
     */
    @GetMapping("/overviewSetmeals")
    @ApiOperation("套餐总览接口")
    public Result<SetmealOverViewVO> overviewSetmeals() {
        log.info("工作台：套餐管理");
        return Result.success(workspaceService.overviewSetmeals());
    }
}
